#pragma once
#include "Socket.h"
#include "Channel.h"


class EventLoop;

// acceptor 仅和mainloop交互

class Acceptor
{

public:
    using NewConnectionCallback = std::function<void(int sockfd_, const InetAddress&)>;

    Acceptor(EventLoop *loop, const InetAddress &listenAddr, bool reuseport);
    ~Acceptor();

    void setNewConnectionCallback(NewConnectionCallback back) {newConnectionCallback_ = back;}

    bool listenning() const {return listenning_;}

    void listen();

private:
    void handleRead();
    
    EventLoop *loop_;
    
    // 用于创建socker 监听端口等
    Socket acceptSocket_;
    // 用于分发请求
    Channel acceptChannel_;
    //即分发给workloop处理线程连接
    NewConnectionCallback newConnectionCallback_;
    bool listenning_;

};

